home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / xmore.arc / XMORE.C next >
C/C++ Source or Header  |  1990-05-01  |  3KB  |  159 lines

  1. #include <stdio.h>
  2. #include <tos.h>
  3. #include <ext.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7. #include <mydefs.h>
  8.  
  9. long    buf[8000];
  10. long    *scb;
  11.  
  12. void savescreen(void)
  13.     {
  14.     long c;
  15.     
  16.     for(c=0L;c<8000;c++)
  17.         buf[c]=*(scb+c);
  18.         
  19.     }
  20.  
  21. void restscreen(void)
  22.     {
  23.     long c;
  24.     
  25.     for (c=0L;c<8000;c++)
  26.         *(scb+c)=buf[c];
  27.     }
  28.  
  29. void moredeg(char *name)
  30.     {
  31.     int fd;
  32.     
  33.     savescreen();
  34.     fd=Fopen(name,READ);
  35.     Fread(fd,34,scb); 
  36.     Fread(fd,32000,scb);
  37.     Fclose(fd);
  38.     while(kbhit())
  39.         getchar();
  40.     while(!kbhit());
  41.     restscreen();
  42.     }
  43.  
  44. void moredoo(char *name)
  45.     {
  46.     int fd;
  47.     
  48.     savescreen();
  49.     fd=Fopen(name,READ);
  50.     Fread(fd,32000,scb);
  51.     Fclose(fd);
  52.     while(kbhit())
  53.         getchar();
  54.     while(!kbhit());
  55.     restscreen();
  56.     }
  57.  
  58. int extcmp(char *s1, char *s2)
  59.     {
  60.     while ((*s1!=0)&&(*s2!='='))
  61.         if (*s1!=*s2)
  62.             return(0);
  63.         else
  64.             {
  65.             ++s1;
  66.             ++s2;
  67.             }
  68.     return(1);
  69.     }
  70.  
  71. void morerun(
  72.     char    *shellp,
  73.     char    *name,
  74.     char    *progname)
  75.     {
  76.     char *p;
  77.     char prog[128];
  78.     COMMAND line;
  79.     line.command_tail[0]=0;
  80.     
  81.     if ((p=strrchr(progname,','))!=NULL)
  82.         {
  83.         strcpy(line.command_tail,p+1);
  84.         strcat(line.command_tail," ");
  85.         }
  86.     else
  87.         p=progname+strlen(progname);
  88.     strncpy(prog,progname,(long)(p-progname));
  89.     strcat(line.command_tail,name);
  90.     line.length=strlen(line.command_tail);
  91.     printf("%s %s\n",prog,line.command_tail);
  92.     Pexec(0,prog,&line,shellp);
  93.     }
  94.  
  95. void moreext(
  96.     char    *shellp,
  97.     char    *name)
  98.     {
  99.     char ext[4];
  100.     char *sp;
  101.     char *p;
  102.     int     i,flag;
  103.     
  104.     strncpy(ext,(p=(strrchr(name,'.')+1)),3);
  105.     if ((p==NULL)||(p==name))
  106.         ext[0]=0;
  107.     for(i=0;i<3;i++)
  108.         if (islower(ext[i]))
  109.             ext[i]=toupper(ext[i]);
  110.     ext[3]=0;
  111.     sp=shellp;
  112.     for(flag=0;flag!=2;flag++)
  113.         {
  114.         shellp=sp;
  115.         while (*shellp != 0)
  116.             {
  117.             if ((*shellp == 'M')&&(*(shellp+1) == 'O')&&(*(shellp+2) == 'R')&&(*(shellp+3) == 'E'))
  118.                 if (extcmp(ext,shellp+4))
  119.                     {
  120.                     morerun(sp,name,shellp+5+strlen(ext));
  121.                     flag=1;
  122.                     }
  123.             shellp+=strlen(shellp)+1;
  124.             }
  125.         strcpy(ext,"DFT");
  126.         }
  127.     }
  128.  
  129. int main(
  130.     int        argc,
  131.     char    **argv,
  132.     char    *shellp)
  133.     {
  134.     char    name[16];
  135.     long    l;
  136.     
  137.     scb=Physbase();
  138.     puts("eXtended More V1.0 by Gregory Mathias Lemperle-Kerr\007");
  139.     if (argc)
  140.         {
  141.         strcpy(name,argv[argc-1]);
  142.         if (Fsfirst(name,0)<0)
  143.             puts("Not Found!\007");
  144.         else
  145.             {
  146.             Fgetdta();
  147.             l=strlen(name);
  148.             if (((name[l-3]=='P')&&(name[l-2]=='I'))||((name[l-3]=='p')&&(name[l-2]=='i')))
  149.                 moredeg(name);
  150.             else if (((name[l-3]=='D')&&(name[l-1]=='O'))||((name[l-3]=='d')&&(name[l-1]=='o')))
  151.                 moredoo(name);
  152.             else
  153.                 moreext(shellp,name);
  154.             }
  155.         }
  156.     else
  157.         puts("Need an argument\007!");
  158.     return(0);
  159.     }